#!/usr/bin/env python
import os
from datetime import datetime

from django.http import HttpResponse,JsonResponse

from fruitshop import settings

def uploadImg(request):
    imgObj = request.FILES.get('file')

    imgName = str(int(datetime.today().timestamp())) + imgObj.name

    imgPath = os.path.join(settings.MEDIA_ROOT,imgName)

    with open(imgPath,'wb') as imgFile:
        data = imgObj.file.read()
        imgFile.write(data)

    return JsonResponse({
        'location':'/media/' + imgName
    })
